package net.wenku8.reader.view.rank

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.lifecycle.viewmodel.compose.viewModel
import net.wenku8.reader.ui.lite.LiteInput
import net.wenku8.reader.ui.lite.LiteLine
import net.wenku8.reader.ui.lite.LitePanel
import net.wenku8.reader.ui.lite.LiteTextButton
import net.wenku8.reader.view.online.OnlineBookPreview


@Composable
fun Search() {
    val searchViewModel = viewModel<SearchViewModel>()

    LaunchedEffect(Unit) {
        searchViewModel.initData()
    }
    LitePanel(
        hostState = searchViewModel.hostState,
        title = "文库搜索",
        backNav = true
    ) {
        Column{
            LiteInput("书名/作者", searchViewModel.key)
            LiteLine {
                LiteTextButton(text = "搜书名") {
                    searchViewModel.onSearch("articlename")
                }
                LiteTextButton(text = "搜作者") {
                    searchViewModel.onSearch("author")
                }
            }
            LazyColumn{
                items(items = searchViewModel.bookList) { book ->
                    OnlineBookPreview(book)
                }
            }
        }
    }


}


